<template>

  <div class="app-container flex-column">
    <div class="flex-between mt10 mb10">
      <div>
        <span class="ml5">登录名称：</span>
        <el-input style="width: 200px;" v-model="userName" placeholder="请输入用户名称" clearable @change="handleQuery" />
      </div>
      <div>

      </div>
    </div>

    <div style="flex: 1;overflow: auto;">
      <el-table ref="tables"    :data="tableList.slice((currentpage-1)*pagesize,currentpage*pagesize)"   height="100%" :row-class-name="tableRowClassName" border stripe
        highlight-current-row>
        <el-table-column label="序号" width="60" header-align="center" align="center" show-overflow-tooltip>
          <template scope="scope">
            <span>{{ (currentpage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="会话编号" align="center" prop="token" :show-overflow-tooltip="true" />
        <el-table-column label="登录名称" align="center" prop="nick_name" :show-overflow-tooltip="true" />
        <el-table-column label="部门名称" align="center" prop="dept_name" show-overflow-tooltip show-overflow-tooltip/>
        <el-table-column label="主机" align="center" prop="ipaddr" :show-overflow-tooltip="true" />
        <el-table-column label="登录地点" align="center" prop="location" :show-overflow-tooltip="true" />
        <el-table-column label="浏览器" align="center" prop="browser" show-overflow-tooltip/>
        <el-table-column label="操作系统" align="center" prop="os" show-overflow-tooltip/>
        <el-table-column label="登录时间" align="center" prop="login_time" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.login_time) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleForceLogout(scope.row)"
              v-hasPermi="['monitor:online:forceLogout']">强退</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="mb20">
      <pagination v-show="total > 0" :total="total" :page.sync="currentpage" :limit.sync="pagesize" />
    </div>

  </div>


</template>

<script>
  import {
    list,
    forceLogout
  } from "@/api/monitor/online";

  export default {
    name: "Online",

    data() {
      return {
        total: 0,
        currentpage: 1,
        pagesize: 5,
        // 岗位表格数据
        tableList: [],
        // 查询参数
        queryParams: {},
        getindex: -1,
        userName: ''
      }
    },

    created() {
      this.getList();
    },
    methods: {
      /** 查询登录日志列表 */
      getList() {
        this.getindex = -1;
        var Params = {

        }
        list(Params).then(response => {
          this.tableList = response.rows;
          this.total = parseInt(response.total);
        });

      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 强退按钮操作 */
      handleForceLogout(row) {
        var params={
          key:row.key
        }
        this.$modal.confirm('是否确认强退名称为"' + row.nick_name + '"的用户？').then(function() {
          return forceLogout(params);
        }).then(() => {
          this.tableList=[];
          this.getList();
          this.$modal.msgSuccess("强退成功");
        }).catch(() => {});
      },

      tableRowClassName({
        row,
        rowIndex
      }) {
        row.index = rowIndex;
      },
      getrow(row) {
        this.getindex = row.index;
      }
    }
  };
</script>
